import utils from '~/utils/utils'
import cookie from 'js-cookie'

export default function ({route, req, res, redirect}) {
  let isClient = process.client;
  let isServer = process.server;
  let redirectURL = '/login';
  var token, path
 if (isServer) {
    let cookies = utils.getcookiesInServer(req)
    path = req.originalUrl;
    token = cookies.en_token ? cookies.en_token : ''
  }

 if (isClient) {
    token = utils.getcookiesInClient('en_token')
    path = route.path;
  }

  if (path == '/') {
    redirectURL = '/'
  }
  console.log(token)
 if (token == '') {
       redirect(redirectURL)
  }
}
